package svc

import (
	"fmt"

	"server_1.0/service/student/internal/config"
	"server_1.0/service/student/model"

	_ "github.com/lib/pq"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

type ServiceContext struct {
	Config       config.Config
	StudentModel model.StudentModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	psqlcfg := c.Postgresql
	DataSource := fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=disable",
		psqlcfg.User,
		psqlcfg.Password,
		psqlcfg.Host,
		psqlcfg.Port,
		psqlcfg.Name,
	)
	conn := sqlx.NewSqlConn("postgres", DataSource)
	return &ServiceContext{
		Config:       c,
		StudentModel: model.NewStudentModel(conn),
	}
}
